<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../header.jsp"%>
<script type="text/javascript">

var detailValidator;

function saveDetail() {
	if (!detailValidator.form()) {
		return;
	}
	doSaveDetail();
}

function doSaveDetail() {
	var data = {
			id : $("#templateId").val(),
			name : $("#templateName").val(),
			specialId: $("#templateSpecialId").val(),	
			constructionModelId: $("#constructionModelId").val(),	
			description : $("#templateDesc").val()
		};
	
	block("detailForm");
	$.ajax({
		type: "POST",
		url: "save.json",
		data: data,
		dataType: "json",
		success: saveSucceedCallback,
		error:function(message){
			unblock("detailForm");
			$.alert(message);
		}  
	});
}

function saveSucceedCallback(data) {
	unblock("detailForm");
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}

	$.info("已保存");
	document.location.href = "./edit.do?id="+data.data.id;
}

$(document).ready(function() {
	$("#templateSpecialId").data("id",$("#specialId").val());

	detailValidator = $("#detailForm").validate({
		rules: {
			templateName:{required:true, maxlength:50},
			templateSpecialId:{required:true, maxlength:50},
			constructionModelId:{required:true, maxlength:50},
			templateDesc:{maxlength:255}
		},
		messages:{
			templateName:{required:"请输入名称"},
			templateSpecialId:{required:"请选择专业"},
			constructionModelId:{required:"请选择工程建设模式"}
		}
	});
	$().maxlength();

});

</script>

<div class="border bg">

<div class="page-header">
<h2>新增模板 <small></small></h2>
<div class="cms_toolbar"><a href="./" class="btn"><i class="icon-list"></i>返回</a></div>
</div> 

<form id="detailForm" class="form-horizontal">
<input type="hidden" id="templateId" value="${data.id}">
<input type="hidden" id="specialId" value="${data.specialId}">
<input type="hidden" id="creatorId" value="${data.creatorId}">

<fieldset>
	<div class="control-group">
		<label for="templateName" class="control-label">名称：</label>
		<div class="controls">
			<input type="text" id="templateName" name="templateName" maxlength="50" value="${data.name}"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="templateSpecialId" class="control-label">专业：</label>
		<div class="controls">
			<select name="templateSpecialId" id="templateSpecialId">				
				<c:forEach var="special" items="${specials}">
					<option value="${special.id}">${special.name}</option>
				</c:forEach>
			</select>	
			<span class="cms_color_required" id="templateRequired">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="constructionModelId" class="control-label">工程建设模式：</label>
		<div class="controls">
			<select name="constructionModelId" id="constructionModelId">
				<option value="">---请选择---</option>
				<c:forEach var="constructionModel" items="${constructionModels}">
					<option value="${constructionModel.id}">${constructionModel.name}</option>
				</c:forEach>
			</select>
		</div>
	</div>
	
	<div class="control-group">
		<label for="templateDesc" class="control-label">描述：</label>
		<div class="controls">
			<textarea id="templateDesc" name="templateDesc" maxlength="1000">${data.description}</textarea>
		</div>
	</div>
	<div class="form-actions">
		<a id="saveButton" href="javascript:;" class="btn btn-primary" onclick="saveDetail()"><i class="icon-ok"></i>保存</a>
	</div>
</fieldset>

</form> 

</div>

<%@ include file="../../../footer.jsp"%>
